package com.inspur.ourhis_afterend.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Dao.DrugsDao;
import com.inspur.ourhis_afterend.Service.PrescribeService;
import com.inspur.ourhis_afterend.Tools.PageAction;
import com.inspur.ourhis_afterend.mapper.DrugsMapper;
import com.inspur.ourhis_afterend.mapper.PrescribeDrugsMapper;
import com.inspur.ourhis_afterend.mapper.PrescribeMapper;
import com.inspur.ourhis_afterend.model.Prescribe;
import com.inspur.ourhis_afterend.model.PrescribeDrugs;
import com.inspur.ourhis_afterend.vo.PrescribeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PrescribeServiceImpl implements PrescribeService {
    @Resource
    DrugsDao drugsDao;
    @Resource
    DrugsMapper drugsMapper;
    @Resource
    PrescribeMapper prescribeMapper;
    @Resource
    PrescribeDrugsMapper prescribeDrugsMapper;


    @Override
    public IPage<PrescribeVo> findByMandRid(IPage<PrescribeVo> iPage, String memeberid, String roid) {
        return drugsMapper.findByMandRid(iPage,memeberid,roid);
    }

    @Override
    public IPage<PrescribeVo> selectAll(String memeberid, String roid) {
        return null;
    }


//    @Override
//    public IPage<PrescribeVo> selectAll(String memeberid, String roid) {
//        return drugsMapper.findByMandRid(memeberid,roid);
//    }

    @Override
    public List<PrescribeVo> findByRoid(Integer roid) {
        return prescribeMapper.findByRoid(roid);
    }

    @Override
    public int updateByRoid(Integer prescribeid) {
        List<PrescribeDrugs> list = prescribeDrugsMapper.selectByPrimaryKey(prescribeid);
        for (PrescribeDrugs prescribeDrugs:list){
            int count2 = prescribeDrugs.getNum();
            int drugid = prescribeDrugs.getDrugsid();
            drugsMapper.updateById(drugid,-count2);
        }
        return prescribeMapper.updateByRoid(prescribeid);
    }

    @Override
    public int insertSelective(Prescribe record) {
        return prescribeMapper.insertSelective(record);
    }
}
